SNA Descritive Analysis from “Projeto Redes de Atenção às pessoas que consomem álcool e outras Drogas em Juiz de Fora-MG Brazil” - SNArRDJF
Here you can find a basic script to analysis data from SNArRDJF - this script was elaborated considering its use for orther matrix adjacency data from SNArRDJF - Here we are going to analyse:
########################## Basic Preparation ##### `#########################
rm(list = ls()) # removing previous objects to be sure that we don't have objects conflicts name
load("~/SNArRDJF/Robject/full_no_zero_data.RData")
suppressMessages(library(RColorBrewer))
#suppressMessages(library(car))
#suppressMessages(library(xtable))
suppressMessages(library(igraph))
#suppressMessages(library(miniCRAN))
#suppressMessages(library(magrittr))
#suppressMessages(library(keyplayer))
#suppressMessages(library(dplyr))
#suppressMessages(library(feather))
#suppressMessages(library(visNetwork))
#suppressMessages(library(knitr))
suppressMessages(library(DT))
#In order to get dinamic javascript object install those ones. If you get problems installing go to Stackoverflow.com and type your error to discover what to do. In some cases the libraries need to be intalled in outside R libs.
#devtools::install_github("wch/webshot")
#webshot::install_phantomjs()
set.seed(123)
#full_no_zero<-simplify(full_no_zero) #Simplify
• For undirected graphs:
– Actor centrality - involvement (connections) with other actors
• For directed graphs:
– Actor centrality - source of the ties (outgoing edges)
– Actor prestige - recipient of many ties (incoming edges)
In general - high centrality degree means direct contact with many other actors
V(full_no_zero)$indegree<-degree(full_no_zero, mode = "in") # Actor prestige - recipient of many ties (incoming edges)
V(full_no_zero)$outdegree <- degree(full_no_zero, mode = "out") # Actor centrality - source of the ties (outgoing edges)
V(full_no_zero)$totaldegree <- degree(full_no_zero, mode = "total")
full_no_zero_indegree<-degree(full_no_zero, mode = "in")
full_no_zero_outdegree<-degree(full_no_zero, mode = "out")
full_no_zero_totaldegree<-degree(full_no_zero, mode = "total")
##in
summary(full_no_zero_indegree)
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## 0.000 4.000 5.000 8.449 9.000 106.000
sd(full_no_zero_indegree)
## [1] 10.84105
hist(degree(full_no_zero, mode = "in", normalized = F), ylab="Frequency", xlab="Degree", breaks=vcount(full_no_zero)/10, main="Histogram of Indegree Nodes - 1.1 - REDE COMPLETA (full_no_zero)")
##out
summary(full_no_zero_outdegree)
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## 0.000 1.000 4.000 8.449 8.500 105.000
sd(full_no_zero_outdegree)
## [1] 13.98391
hist(degree(full_no_zero, mode = "out", normalized = F), ylab="Frequency", xlab="Degree", breaks=vcount(full_no_zero)/10, main="Histogram of Outdegree Nodes - 1.1 - REDE COMPLETA (full_no_zero)")
##all
summary(full_no_zero_totaldegree)
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## 1.0 5.0 10.0 16.9 18.0 211.0
sd(full_no_zero_totaldegree)
## [1] 23.45518
hist(degree(full_no_zero, mode = "all", normalized = F), ylab="Frequency", xlab="Degree", breaks=vcount(full_no_zero)/10, main="Histogram of All Degree Nodes - 1.1 - REDE COMPLETA (full_no_zero)")
A slightly more nuanced metric is “strength centrality”, which is defined as the sum of the weights of all the connections for a given node. This is also sometimes called “weighted degree centrality”
V(full_no_zero)$full_no_zero_strength<- strength(full_no_zero, weights=E(full_no_zero)$weight)
full_no_zero_strength<- strength(full_no_zero, weights=E(full_no_zero)$weight)
summary(full_no_zero_strength)
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## 1.0 5.0 10.0 16.9 18.0 211.0
sd(full_no_zero_strength)
## [1] 23.45518
hist(strength(full_no_zero, weights=E(full_no_zero)$weight), ylab="Frequency", xlab="Degree", breaks=vcount(full_no_zero)/10, main="Histogram of Strength Degree Nodes - 1.1 - REDE COMPLETA (full_no_zero)")
V(full_no_zero)$indegree_n<-degree(full_no_zero, mode = "in", normalized = T)
V(full_no_zero)$outdegree_n<- degree(full_no_zero, mode = "out", normalized = T)
V(full_no_zero)$totaldegree_n<- degree(full_no_zero, mode = "total", normalized = T)
full_no_zero_indegree_n<-degree(full_no_zero, mode = "in", normalized = T)
full_no_zero_outdegree_n<-degree(full_no_zero, mode = "out", normalized = T)
full_no_zero_totaldegree_n<-degree(full_no_zero, mode = "total", normalized = T)
summary(full_no_zero_indegree_n)
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## 0.00000 0.02151 0.02688 0.04543 0.04839 0.56990
sd(full_no_zero_indegree_n)
## [1] 0.0582852
hist(degree(full_no_zero, mode = "in", normalized = T), ylab="Frequency", xlab="Normalized Degree", breaks=vcount(full_no_zero)/10, main="Histogram of Normalized Indegree Nodes - 1.1 - REDE COMPLETA (full_no_zero)")
summary(full_no_zero_outdegree_n)
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## 0.000000 0.005376 0.021510 0.045430 0.045700 0.564500
sd(full_no_zero_outdegree_n)
## [1] 0.07518233
hist(degree(full_no_zero, mode = "out", normalized = T), ylab="Frequency", xlab="Normalized Degree", breaks=vcount(full_no_zero)/10, main="Histogram of Normalized Outdegree Nodes - 1.1 - REDE COMPLETA (full_no_zero)")
summary(full_no_zero_totaldegree_n)
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## 0.005376 0.026880 0.053760 0.090850 0.096770 1.134000
sd(full_no_zero_totaldegree_n)
## [1] 0.1261031
hist(degree(full_no_zero, mode = "all", normalized = T), ylab="Frequency", xlab="Normalized Degree", breaks=vcount(full_no_zero)/10, main="Histogram of Normalized All Degree Nodes - 1.1 - REDE COMPLETA (full_no_zero)")
V(full_no_zero)$full_no_zero_centr_degree <- centralization.degree(full_no_zero)$res
full_no_zero_centr_degree <- centralization.degree(full_no_zero)
full_no_zero_centr_degree$centralization
## [1] 0.5245838
full_no_zero_centr_degree$theoretical_max
## [1] 69192
full_no_zero_degree.distribution<-degree.distribution(full_no_zero)
summary(full_no_zero_degree.distribution)
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## 0.000000 0.000000 0.000000 0.004717 0.000000 0.107000
sd(full_no_zero_degree.distribution)
## [1] 0.01451276
hist(degree.distribution(full_no_zero), breaks=vcount(full_no_zero)/10, ylab="Frequency", xlab="Degree Distribuition", main="Histogram of Degree Distribuition - 1.1 - REDE COMPLETA (full_no_zero)")
dd <- degree.distribution(full_no_zero, cumulative=T, mode="all")
plot(dd, pch=19, cex=1, col="orange", xlab="Degree", ylab="Cumulative Frequency", main= "Cumulative Frequency of 1.1 - REDE COMPLETA (full_no_zero) ")
dd.full_no_zero <- degree.distribution(full_no_zero)
d <- 1:max(degree(full_no_zero))-1
ind <- (dd.full_no_zero != 0)
plot(d[ind],
dd.full_no_zero[ind],
log="xy",
col="blue",
xlab=c("Log-Degree"),
ylab=c("Log-Intensity"),
main="Log-Log Degree Distribution For 1.1 - REDE COMPLETA (full_no_zero)"
)
The neighborhood of a given order y of a vertex v includes all vertices which are closer to v than the order. Ie. order y=0 is always v itself, order 1 is v plus its immediate neighbors, order 2 is order 1 plus the immediate neighbors of the vertices in order 1, etc.
full_no_zero_simplified<-simplify(full_no_zero)
full_no_zero_a.nn.deg <- graph.knn(full_no_zero_simplified, weights =E(full_no_zero_simplified)$weight)$knn %>% round(1)
V(full_no_zero_simplified)$full_no_zero_a.nn.deg <- graph.knn(full_no_zero_simplified, weights=E(full_no_zero_simplified)$weight)$knn
d<-cbind(V(full_no_zero_simplified)$LABEL_COR,full_no_zero_a.nn.deg)
datatable(d)
plot(degree(full_no_zero_simplified),
full_no_zero_a.nn.deg,
log="xy",
col="goldenrod",
xlab=c("Log Vertex Degree"),
ylab=c("Log Average Neighbor Degree"),
main="Average Neighbor Degree vs Vertex Degree - Log-Log Scale for 1.1 - REDE COMPLETA (full_no_zero)"
)
full_no_zero_a.nn.deg_w <- graph.knn(full_no_zero_simplified, weights=E(full_no_zero_simplified)$weight)$knn %>% round(1)
V(full_no_zero_simplified)$full_no_zero_a.nn.deg_w <-full_no_zero_a.nn.deg <- graph.knn(full_no_zero_simplified, weights=E(full_no_zero_simplified)$weight)$knn
summary(full_no_zero_a.nn.deg_w)
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## 4.00 36.30 51.90 62.04 83.85 211.00
sd(full_no_zero_a.nn.deg_w, na.rm = T)
## [1] 36.88108
d<-cbind(V(full_no_zero_simplified)$LABEL_COR,full_no_zero_a.nn.deg_w)
datatable(d)
plot(degree(full_no_zero_simplified),
full_no_zero_a.nn.deg,
log="xy",
col="goldenrod",
xlab=c("Log Vertex Degree"),
ylab=c("Log Average Neighbor Degree"),
main="Average Weighted Neighbor Degree vs Vertex Degree - Log-Log Scale For Weighted 1.1 - REDE COMPLETA (full_no_zero)"
)
full_no_zero_indegree<-degree(full_no_zero, mode = "in")
full_no_zero_outdegree<-degree(full_no_zero, mode = "out")
full_no_zero_totaldegree<-degree(full_no_zero, mode = "total")
full_no_zero_strength<- strength(full_no_zero, weights=E(full_no_zero)$weight)
full_no_zero_indegree_n<-degree(full_no_zero, mode = "in", normalized = T) %>% round(3)
full_no_zero_outdegree_n<-degree(full_no_zero, mode = "out", normalized = T) %>% round(3)
full_no_zero_totaldegree_n<-degree(full_no_zero, mode = "total", normalized = T) %>% round(3)
full_no_zero_centr_degree <- centralization.degree(full_no_zero)$res
full_no_zero_a.nn.deg <- graph.knn(full_no_zero_simplified)$knn %>% round(1)
full_no_zero_a.nn.deg_w <- graph.knn(full_no_zero_simplified, weights=E(full_no_zero_simplified)$weight)$knn %>% round(1)
full_no_zero_df_degree <- data.frame(full_no_zero_indegree,
full_no_zero_outdegree,
full_no_zero_totaldegree,
full_no_zero_indegree_n,
full_no_zero_outdegree_n,
full_no_zero_totaldegree_n,
full_no_zero_strength,
full_no_zero_centr_degree,
full_no_zero_a.nn.deg,
full_no_zero_a.nn.deg_w) %>% round(3)
#Adding type
full_no_zero_df_degree <-cbind(full_no_zero_df_degree, V(full_no_zero)$LABEL_COR)
#Adding names
names(full_no_zero_df_degree) <- c("In Degree", "Out Degree", "Total Degree","In Degree Normalized", "Out Degree Normalized", "Total Degree Normalized", "Strength","Centralization Degree","Average Neighbor Degree","Average Weighted Neighbor Degree","Type")
#Ordering Variables
full_no_zero_df_degree<-full_no_zero_df_degree[c("Type","In Degree", "Out Degree", "Total Degree","In Degree Normalized", "Out Degree Normalized", "Total Degree Normalized", "Strength","Centralization Degree","Average Neighbor Degree","Average Weighted Neighbor Degree")]
datatable(full_no_zero_df_degree, filter = 'top')
aggdata_mean <-aggregate(full_no_zero_df_degree, by=list(full_no_zero_df_degree$Type), FUN=mean, na.rm=TRUE)
#Removing Type variable
aggdata_mean<-aggdata_mean[,-c(2)]
names(aggdata_mean) <- c("Group", "In Degree(M)", "Out Degree(M)", "Total Degree(M)","In Degree Normalized(M)", "Out Degree Normalized(M)", "Total Degree Normalized(M)", "Strength(M)","Centralization Degree(M)","Average Neighbor Degree(M)","Average Weighted Neighbor Degree(M)")
aggdata_sd <-aggregate(full_no_zero_df_degree, by=list(full_no_zero_df_degree$Type), FUN=sd, na.rm=TRUE)
#Removing Type variable
aggdata_sd<-aggdata_sd[,-c(2)]
names(aggdata_sd) <- c("Group", "In Degree(SD)", "Out Degree(SD)", "Total Degree(SD)","In Degree Normalized(SD)", "Out Degree Normalized(SD)", "Total Degree Normalized(SD)", "Strength(SD)","Centralization Degree(SD)","Average Neighbor Degree(SD)","Average Weighted Neighbor Degree(SD)")
total_table <- merge(aggdata_mean,aggdata_sd,by="Group")
#Rounding
Group<-total_table[,c(1)] #Keeping group
total_table<-total_table[,-c(1)] %>% round(2) #Rouding
total_table<-cbind(Group,total_table) #Binding toghter
#Organizing Variabels
total_table<-total_table[c("Group","In Degree(M)","In Degree(SD)", "Out Degree(M)", "Out Degree(SD)","Total Degree(M)", "Total Degree(SD)", "In Degree Normalized(M)", "In Degree Normalized(SD)", "Out Degree Normalized(M)", "Out Degree Normalized(SD)", "Total Degree Normalized(M)", "Total Degree Normalized(SD)", "Strength(M)","Strength(SD)", "Centralization Degree(M)","Centralization Degree(SD)","Average Neighbor Degree(M)","Average Neighbor Degree(SD)","Average Weighted Neighbor Degree(M)", "Average Weighted Neighbor Degree(SD)")]
datatable(total_table, filter = 'top')
full_no_zero_df_degree <- data.frame(full_no_zero_indegree,
full_no_zero_outdegree,
full_no_zero_totaldegree,
full_no_zero_indegree_n,
full_no_zero_outdegree_n,
full_no_zero_totaldegree_n,
full_no_zero_strength,
full_no_zero_centr_degree,
full_no_zero_a.nn.deg,
full_no_zero_a.nn.deg_w) %>% round(3)
#Adding type
full_no_zero_df_degree <-cbind(full_no_zero_df_degree, V(full_no_zero)$TIPO1)
#Adding names
names(full_no_zero_df_degree) <- c("In Degree", "Out Degree", "Total Degree","In Degree Normalized", "Out Degree Normalized", "Total Degree Normalized", "Strength","Centralization Degree","Average Neighbor Degree","Average Weighted Neighbor Degree","Type")
#Ordering Variables
full_no_zero_df_degree<-full_no_zero_df_degree[c("Type","In Degree", "Out Degree", "Total Degree","In Degree Normalized", "Out Degree Normalized", "Total Degree Normalized", "Strength","Centralization Degree","Average Neighbor Degree","Average Weighted Neighbor Degree")]
datatable(full_no_zero_df_degree, filter = 'top')
aggdata_mean <-aggregate(full_no_zero_df_degree, by=list(full_no_zero_df_degree$Type), FUN=mean, na.rm=TRUE)
#Removing Type variable
aggdata_mean<-aggdata_mean[,-c(2)]
names(aggdata_mean) <- c("Group", "In Degree(M)", "Out Degree(M)", "Total Degree(M)","In Degree Normalized(M)", "Out Degree Normalized(M)", "Total Degree Normalized(M)", "Strength(M)","Centralization Degree(M)","Average Neighbor Degree(M)","Average Weighted Neighbor Degree(M)")
aggdata_sd <-aggregate(full_no_zero_df_degree, by=list(full_no_zero_df_degree$Type), FUN=sd, na.rm=TRUE)
#Removing Type variable
aggdata_sd<-aggdata_sd[,-c(2)]
names(aggdata_sd) <- c("Group", "In Degree(SD)", "Out Degree(SD)", "Total Degree(SD)","In Degree Normalized(SD)", "Out Degree Normalized(SD)", "Total Degree Normalized(SD)", "Strength(SD)","Centralization Degree(SD)","Average Neighbor Degree(SD)","Average Weighted Neighbor Degree(SD)")
total_table <- merge(aggdata_mean,aggdata_sd,by="Group")
#Rounding
Group<-total_table[,c(1)] #Keeping group
total_table<-total_table[,-c(1)] %>% round(2) #Rouding
total_table<-cbind(Group,total_table) #Binding toghter
#Organizing Variabels
total_table<-total_table[c("Group","In Degree(M)","In Degree(SD)", "Out Degree(M)", "Out Degree(SD)","Total Degree(M)", "Total Degree(SD)", "In Degree Normalized(M)", "In Degree Normalized(SD)", "Out Degree Normalized(M)", "Out Degree Normalized(SD)", "Total Degree Normalized(M)", "Total Degree Normalized(SD)", "Strength(M)","Strength(SD)", "Centralization Degree(M)","Centralization Degree(SD)","Average Neighbor Degree(M)","Average Neighbor Degree(SD)","Average Weighted Neighbor Degree(M)", "Average Weighted Neighbor Degree(SD)")]
datatable(total_table, filter = 'top')
full_no_zero_df_degree <- data.frame(full_no_zero_indegree,
full_no_zero_outdegree,
full_no_zero_totaldegree,
full_no_zero_indegree_n,
full_no_zero_outdegree_n,
full_no_zero_totaldegree_n,
full_no_zero_strength,
full_no_zero_centr_degree,
full_no_zero_a.nn.deg,
full_no_zero_a.nn.deg_w) %>% round(3)
#Adding type
full_no_zero_df_degree <-cbind(full_no_zero_df_degree, V(full_no_zero)$TIPO2)
#Adding names
names(full_no_zero_df_degree) <- c("In Degree", "Out Degree", "Total Degree","In Degree Normalized", "Out Degree Normalized", "Total Degree Normalized", "Strength","Centralization Degree","Average Neighbor Degree","Average Weighted Neighbor Degree","Type")
#Ordering Variables
full_no_zero_df_degree<-full_no_zero_df_degree[c("Type","In Degree", "Out Degree", "Total Degree","In Degree Normalized", "Out Degree Normalized", "Total Degree Normalized", "Strength","Centralization Degree","Average Neighbor Degree","Average Weighted Neighbor Degree")]
datatable(full_no_zero_df_degree, filter = 'top')
aggdata_mean <-aggregate(full_no_zero_df_degree, by=list(full_no_zero_df_degree$Type), FUN=mean, na.rm=TRUE)
#Removing Type variable
aggdata_mean<-aggdata_mean[,-c(2)]
names(aggdata_mean) <- c("Group", "In Degree(M)", "Out Degree(M)", "Total Degree(M)","In Degree Normalized(M)", "Out Degree Normalized(M)", "Total Degree Normalized(M)", "Strength(M)","Centralization Degree(M)","Average Neighbor Degree(M)","Average Weighted Neighbor Degree(M)")
aggdata_sd <-aggregate(full_no_zero_df_degree, by=list(full_no_zero_df_degree$Type), FUN=sd, na.rm=TRUE)
#Removing Type variable
aggdata_sd<-aggdata_sd[,-c(2)]
names(aggdata_sd) <- c("Group", "In Degree(SD)", "Out Degree(SD)", "Total Degree(SD)","In Degree Normalized(SD)", "Out Degree Normalized(SD)", "Total Degree Normalized(SD)", "Strength(SD)","Centralization Degree(SD)","Average Neighbor Degree(SD)","Average Weighted Neighbor Degree(SD)")
total_table <- merge(aggdata_mean,aggdata_sd,by="Group")
#Rounding
Group<-total_table[,c(1)] #Keeping group
total_table<-total_table[,-c(1)] %>% round(2) #Rouding
total_table<-cbind(Group,total_table) #Binding toghter
#Organizing Variabels
total_table<-total_table[c("Group","In Degree(M)","In Degree(SD)", "Out Degree(M)", "Out Degree(SD)","Total Degree(M)", "Total Degree(SD)", "In Degree Normalized(M)", "In Degree Normalized(SD)", "Out Degree Normalized(M)", "Out Degree Normalized(SD)", "Total Degree Normalized(M)", "Total Degree Normalized(SD)", "Strength(M)","Strength(SD)", "Centralization Degree(M)","Centralization Degree(SD)","Average Neighbor Degree(M)","Average Neighbor Degree(SD)","Average Weighted Neighbor Degree(M)", "Average Weighted Neighbor Degree(SD)")]
datatable(total_table, filter = 'top')
#Set Seed
set.seed(123)
#Plotting based only on degree measures
edge.start <- ends(full_no_zero, es=E(full_no_zero), names=F)[,1]
# Fixing ego
minC <- rep(-Inf, vcount(full_no_zero))
maxC <- rep(Inf, vcount(full_no_zero))
minC[1] <- maxC[1] <- 0
co <- layout_with_fr(full_no_zero, niter=10000, minx=minC, maxx=maxC,miny=minC, maxy=maxC, weights = E(full_no_zero)$weight)
#PLotting
plot(full_no_zero,
layout=co,
edge.color=V(full_no_zero)$color[edge.start],
edge.arrow.size=(degree(full_no_zero)+1)/(30*mean(degree(full_no_zero))),
edge.width=E(full_no_zero)$weight/(10*mean(E(full_no_zero)$weight)),
edge.curved = TRUE,
vertex.size=log((degree(full_no_zero)+2))*(0.5*mean(degree(full_no_zero))),
vertex.frame.color="#ffffff",
vertex.label.color="black",
vertex.label=get.vertex.attribute(full_no_zero,"LABEL_COR"),
vertex.label.cex=log(degree(full_no_zero)+2)/mean(degree(full_no_zero)),
vertex.label.dist=0,
rescale=F,
xlim=range(co[,1]),
ylim=range(co[,2]))
axis(1)
axis(2)
#Solving Problems with legend rendering
a<-V(full_no_zero)$LABEL_COR
b<-V(full_no_zero)$color
c<-table(a,b)
d<-as.data.frame(c)
e<-subset(d, d$Freq>0)
f<-t(e$a)
g<-t(e$b)
#Adding Legend
legend(x=range(co[,1])[2], y=range(co[,2])[2],
legend=as.character(f),
pch=21,
col = "#777777",
pt.bg=as.character(g),
pt.cex=2,
bty="n",
ncol=1,
lty=1,
cex = .5)
#Adding Title
title("Network Vertex Degree Sized - 1.1 - REDE COMPLETA (full_no_zero)", sub = "Source: from authors ", cex = .5)
text(x=range(co[,1])[1], y=range(co[,2])[1], labels =
sprintf("Median In Degree: %.2f\n Median Out Degree: %.2f",
median(degree(full_no_zero, mode="in")),
median(degree(full_no_zero, mode="out"))
))
#Set Seed
set.seed(123)
#Get Variable
V(full_no_zero)$full_no_zero_color_degree<-V(full_no_zero)$totaldegree %>% round(0)
#Creating brewer pallette
vertex_full_no_zero_color_degree<-
colorRampPalette(brewer.pal(length(unique(
V(full_no_zero)$full_no_zero_color_degree)), "RdBu"))(
length(unique(V(full_no_zero)$full_no_zero_color_degree)))
#Saving as Vertex properties
V(full_no_zero)$vertex_full_no_zero_color_degree<- vertex_full_no_zero_color_degree[as.numeric(cut(degree(full_no_zero),breaks =length(unique(V(full_no_zero)$full_no_zero_color_degree))))]
set.seed(123)
#Plotting based only on degree measures
edge.start <- ends(full_no_zero, es=E(full_no_zero), names=F)[,1]
# Fixing ego
minC <- rep(-Inf, vcount(full_no_zero))
maxC <- rep(Inf, vcount(full_no_zero))
minC[1] <- maxC[1] <- 0
co <- layout_with_fr(full_no_zero, niter=10000, minx=minC, maxx=maxC,miny=minC, maxy=maxC, weights = E(full_no_zero)$weight)
#PLotting
plot(full_no_zero,
layout=co,
#edge.color=V(full_no_zero)$color[edge.start],
edge.arrow.size=(degree(full_no_zero)+1)/1000,
edge.width=E(full_no_zero)$weight/10,
edge.curved = TRUE,
vertex.color=V(full_no_zero)$vertex_full_no_zero_color_degree,
vertex.size=log((degree(full_no_zero)+2))*10,
vertex.size=20,
vertex.frame.color="#ffffff",
vertex.label.color="black",
vertex.label=get.vertex.attribute(full_no_zero,"LABEL_COR"),
vertex.label.cex=log((degree(full_no_zero)+2))/10,
vertex.label.dist=0,
rescale=F,
xlim=range(co[,1]),
ylim=range(co[,2]))
axis(1)
axis(2)
#Solving Problems with legend rendering
a<-V(full_no_zero)$full_no_zero_color_degree
b<-V(full_no_zero)$vertex_full_no_zero_color_degree
c<-table(a,b)
d<-as.data.frame(c)
e<-subset(d, d$Freq>0)
e<-e[order(e$a,decreasing=T),]
f<-t(e$a)
g<-t(e$b)
#Adding Legend
legend(x=range(co[,1])[2], y=range(co[,2])[2],
legend=as.character(f),
pch=21,
col = "#777777",
pt.bg=as.character(g),
pt.cex=2,
bty="n",
ncol=1,
lty=1,
cex = .3)
#Adding Title
title("Network Vertex Degree Sized and Red to Blue - 1.1 - REDE COMPLETA (full_no_zero)", sub = "Source: from authors ")
text(x=range(co[,1])[1], y=range(co[,2])[1], labels =
sprintf("Median In Degree: %.2f\nMedian Out Degree: %.2f",
median(degree(full_no_zero, mode="in")),
median(degree(full_no_zero, mode="out"))
))
#Set Seed
set.seed(123)
#Get Variable
V(full_no_zero)$full_no_zero_color_degree<-V(full_no_zero)$full_no_zero_centr_degree
#Creating brewer pallette
vertex_full_no_zero_color_degree<-
colorRampPalette(brewer.pal(length(unique(
V(full_no_zero)$full_no_zero_color_degree)), "Spectral"))(
length(unique(V(full_no_zero)$full_no_zero_color_degree)))
#Saving as Vertex properties
V(full_no_zero)$vertex_full_no_zero_color_degree<- vertex_full_no_zero_color_degree[as.numeric(cut(V(full_no_zero)$full_no_zero_color_degree,breaks =length(unique(V(full_no_zero)$full_no_zero_color_degree))))]
#Plotting based only on degree measures
edge.start <- ends(full_no_zero, es=E(full_no_zero), names=F)[,1]
# Fixing ego
minC <- rep(-Inf, vcount(full_no_zero))
maxC <- rep(Inf, vcount(full_no_zero))
minC[1] <- maxC[1] <- 0
co <- layout_with_fr(full_no_zero, niter=10000, minx=minC, maxx=maxC,miny=minC, maxy=maxC, weights = E(full_no_zero)$weight)
#PLotting
plot(full_no_zero,
layout=co,
edge.color=V(full_no_zero)$vertex_full_no_zero_color_degree[edge.start],
edge.arrow.size=(degree(full_no_zero)+1)/10000,
edge.width=E(full_no_zero)$weight/10,
edge.curved = TRUE,
vertex.color=V(full_no_zero)$vertex_full_no_zero_color_degree,
vertex.size=log((V(full_no_zero)$full_no_zero_centr_degree+2))*10,
vertex.frame.color="#ffffff",
vertex.label.color="black",
vertex.label=get.vertex.attribute(full_no_zero,"LABEL_COR"),
vertex.label.cex=log((degree(full_no_zero)+2))/10,
vertex.label.dist=0,
rescale=F,
xlim=range(co[,1]),
ylim=range(co[,2]))
axis(1)
axis(2)
#Solving Problems with legend rendering
a<-V(full_no_zero)$full_no_zero_color_degree
b<-V(full_no_zero)$vertex_full_no_zero_color_degree
c<-table(a,b)
d<-as.data.frame(c)
e<-subset(d, d$Freq>0)
e<-e[order(e$a,decreasing=T),]
f<-t(e$a)
g<-t(e$b)
#Adding Legend
legend(x=range(co[,1])[2], y=range(co[,2])[2],
legend=as.character(f),
pch=21,
col = "#777777",
pt.bg=as.character(g),
pt.cex=2,
bty="n",
ncol=1,
lty=1,
cex = .3)
#Adding Title
title("Network Vertex Centralization Degree Sized Spectral Colored - 1.1 - REDE COMPLETA (full_no_zero)", sub = "Source: from authors ")
text(x=range(co[,1])[1], y=range(co[,2])[1], labels =
sprintf("Median In Degree: %.2f\nMedian Out Degree: %.2f",
median(degree(full_no_zero, mode="in")),
median(degree(full_no_zero, mode="out"))
))
#Set Seed
set.seed(123)
# Network elements with lower than meadian degree
higherthanmedian.network_full_no_zero<-V(full_no_zero)[degree(full_no_zero)<median(degree(full_no_zero))]
#Deleting vertices based in intersection betewenn full_no_zero
high_full_no_zero<-delete.vertices(full_no_zero, higherthanmedian.network_full_no_zero)
#Plotting based only on degree measures
edge.start <- ends(high_full_no_zero, es=E(high_full_no_zero), names=F)[,1]
# Fixing ego
minC <- rep(-Inf, vcount(high_full_no_zero))
maxC <- rep(Inf, vcount(high_full_no_zero))
minC[1] <- maxC[1] <- 0
co <- layout_with_fr(high_full_no_zero, niter=10000, minx=minC, maxx=maxC,miny=minC, maxy=maxC, weights = E(high_full_no_zero)$weight)
#PLotting
plot(high_full_no_zero,
layout=co,
edge.color=V(high_full_no_zero)$color[edge.start],
edge.arrow.size=(degree(high_full_no_zero)+1)/1000,
edge.width=E(high_full_no_zero)$weight/10,
edge.curved = TRUE,
vertex.size=log((V(high_full_no_zero)$full_no_zero_centr_degree+2))*10,
vertex.frame.color="#ffffff",
vertex.label.color="black",
vertex.label=get.vertex.attribute(high_full_no_zero,"LABEL_COR"),
vertex.label.cex=log((degree(high_full_no_zero)+2))/10,
vertex.label.dist=0,
rescale=F,
xlim=range(co[,1]),
ylim=range(co[,2]))
axis(1)
axis(2)
#Solving Problems with legend rendering
a<-V(high_full_no_zero)$LABEL_COR
b<-V(high_full_no_zero)$color
c<-table(a,b)
d<-as.data.frame(c)
e<-subset(d, d$Freq>0)
f<-t(e$a)
g<-t(e$b)
#Adding Legend
legend(x=range(co[,1])[2], y=range(co[,2])[2],
legend=as.character(f),
pch=21,
col = "#777777",
pt.bg=as.character(g),
pt.cex=3,
bty="n",
ncol=1,
lty=1,
cex = .5)
#Adding Title
title("Network Higher Than Median Degree - 1.1 - REDE COMPLETA (full_no_zero)", sub = "Source: from authors ")
text(x=range(co[,1])[1], y=range(co[,2])[1], labels =
sprintf("Mean In Degree: %.2f\n Mean Out Degree: %.2f",
mean(degree(high_full_no_zero, mode="in")),
mean(degree(high_full_no_zero, mode="out"))
)
)
#Set Seed
set.seed(123)
# Network elements with lower than meadian degree
lowerthanmedian.network_full_no_zero<-V(full_no_zero)[degree(full_no_zero)>median(degree(full_no_zero))]
#Deleting vertices based in intersection betewenn full_no_zero
small_full_no_zero<-delete.vertices(full_no_zero, lowerthanmedian.network_full_no_zero)
#Plotting based only on degree measures
edge.start <- ends(small_full_no_zero, es=E(small_full_no_zero), names=F)[,1]
# Fixing ego
minC <- rep(-Inf, vcount(small_full_no_zero))
maxC <- rep(Inf, vcount(small_full_no_zero))
minC[1] <- maxC[1] <- 0
co <- layout_with_fr(small_full_no_zero, niter=10000, minx=minC, maxx=maxC,miny=minC, maxy=maxC, weights = E(small_full_no_zero)$weight)
#PLotting
plot(small_full_no_zero,
layout=co,
edge.color=V(small_full_no_zero)$color[edge.start],
edge.arrow.size=(degree(small_full_no_zero)+1)/1000,
edge.width=E(small_full_no_zero)$weight/10,
edge.curved = TRUE,
vertex.size=log((V(small_full_no_zero)$full_no_zero_centr_degree+2))*20,
vertex.frame.color="#ffffff",
vertex.label.color="black",
vertex.label=get.vertex.attribute(small_full_no_zero,"LABEL_COR"),
vertex.label.cex=log((degree(small_full_no_zero)+2))/3,
vertex.label.dist=0,
rescale=F,
xlim=range(co[,1]),
ylim=range(co[,2]))
axis(1)
axis(2)
#Solving Problems with legend rendering
a<-V(small_full_no_zero)$LABEL_COR
b<-V(small_full_no_zero)$color
c<-table(a,b)
d<-as.data.frame(c)
e<-subset(d, d$Freq>0)
f<-t(e$a)
g<-t(e$b)
#Adding Legend
legend(x=range(co[,1])[2], y=range(co[,2])[2],
legend=as.character(f),
pch=21,
col = "#777777",
pt.bg=as.character(g),
pt.cex=4,
bty="n",
ncol=1,
lty=1,
cex = .5)
#Adding Title
title("Network Smaller Than Median Degree - 1.1 - REDE COMPLETA (full_no_zero)", sub = "Source: from authors ")
text(x=range(co[,1])[1], y=range(co[,2])[1], labels =
sprintf("Mean In Degree: %.2f\nMean Out Degree: %.2f",
mean(degree(small_full_no_zero, mode="in")),
mean(degree(small_full_no_zero, mode="out"))
)
)
#Set Seed
set.seed(123)
#Plotting based only on degree measures
edge.start <- ends(full_no_zero_simplified, es=E(full_no_zero_simplified), names=F)[,1]
# Fixing ego
minC <- rep(-Inf, vcount(full_no_zero_simplified))
maxC <- rep(Inf, vcount(full_no_zero_simplified))
minC[1] <- maxC[1] <- 0
co <- layout_with_fr(full_no_zero_simplified, niter=10000, minx=minC, maxx=maxC,miny=minC, maxy=maxC, weights = E(full_no_zero_simplified)$weight)
#Plotting based only on degree measures #full_no_zero_simplified_a.nn.deg
V(full_no_zero_simplified)$full_no_zero_a.nn.deg<-as.numeric(graph.knn(full_no_zero_simplified)$knn)
V(full_no_zero_simplified)$full_no_zero_a.nn.deg[V(full_no_zero_simplified)$full_no_zero_a.nn.deg=="NaN"]<-0
#PLotting
plot(full_no_zero_simplified,
layout=co,
edge.color=V(full_no_zero_simplified)$color[edge.start],
edge.arrow.size=sqrt((V(full_no_zero_simplified)$full_no_zero_a.nn.deg)^2+1)/1000,
edge.width=E(full_no_zero_simplified)$weight/100,
edge.curved = TRUE,
vertex.color=V(full_no_zero_simplified)$color,
vertex.size=(sqrt((V(full_no_zero_simplified)$full_no_zero_a.nn.deg)^2))/5,
vertex.frame.color="#ffffff",
vertex.label.color="black",
vertex.label=get.vertex.attribute(full_no_zero_simplified,"LABEL_COR"),
vertex.label.cex=(sqrt((V(full_no_zero_simplified)$full_no_zero_a.nn.deg)^2)+1)/500,
vertex.label.dist=0,
rescale=F,
xlim=range(co[,1]),
ylim=range(co[,2]))
axis(1)
axis(2)
#Solving Problems with legend rendering
a<-V(full_no_zero_simplified)$LABEL_COR
b<-V(full_no_zero_simplified)$color
c<-table(a,b)
d<-as.data.frame(c)
e<-subset(d, d$Freq>0)
f<-t(e$a)
g<-t(e$b)
#Adding Legend
legend(x=range(co[,1])[2], y=range(co[,2])[2],
legend=as.character(f),
pch=21,
col = "#777777",
pt.bg=as.character(g),
pt.cex=4,
bty="n",
ncol=1,
lty=1,
cex = .5)
#Adding Title
title("Network Average Neighbor Degree Sized - 1.1 - REDE COMPLETA (full_no_zero)", sub = "Source: from authors ")
text(x=range(co[,1])[1], y=range(co[,2])[1], labels =
sprintf("Median Average Neighbor Degree: %.2f",
median((full_no_zero_a.nn.deg+1))
))
#Set Seed
set.seed(123)
#Plotting based only on degree measures
edge.start <- ends(full_no_zero_simplified, es=E(full_no_zero_simplified), names=F)[,1]
# Fixing ego
minC <- rep(-Inf, vcount(full_no_zero_simplified))
maxC <- rep(Inf, vcount(full_no_zero_simplified))
minC[1] <- maxC[1] <- 0
co <- layout_with_fr(full_no_zero_simplified, niter=10000, minx=minC, maxx=maxC,miny=minC, maxy=maxC, weights = E(full_no_zero_simplified)$weight)
#Plotting based only on degree measures #full_no_zero_a.nn.deg
V(full_no_zero_simplified)$full_no_zero_a.nn.deg_w<-as.numeric(graph.knn(full_no_zero_simplified, weights = E(full_no_zero_simplified)$weight)$knn)
V(full_no_zero_simplified)$full_no_zero_a.nn.deg_w[V(full_no_zero_simplified)$full_no_zero_a.nn.deg_w=="NaN"]<-0
#PLotting
plot(full_no_zero_simplified,
layout=co,
edge.color=V(full_no_zero_simplified)$color[edge.start],
edge.arrow.size=sqrt((V(full_no_zero_simplified)$full_no_zero_a.nn.deg_w)^2+1)/1000,
edge.width=E(full_no_zero_simplified)$weight/100,
edge.curved = TRUE,
vertex.color=V(full_no_zero_simplified)$color,
vertex.size=(sqrt((V(full_no_zero_simplified)$full_no_zero_a.nn.deg_w)^2))/5,
vertex.frame.color="#ffffff",
vertex.label.color="black",
vertex.label=get.vertex.attribute(full_no_zero_simplified,"LABEL_COR"),
vertex.label.cex=(sqrt((V(full_no_zero_simplified)$full_no_zero_a.nn.deg_w)^2)+1)/500,
vertex.label.dist=0,
rescale=F,
xlim=range(co[,1]),
ylim=range(co[,2]))
axis(1)
axis(2)
#Solving Problems with legend rendering
a<-V(full_no_zero_simplified)$LABEL_COR
b<-V(full_no_zero_simplified)$color
c<-table(a,b)
d<-as.data.frame(c)
e<-subset(d, d$Freq>0)
f<-t(e$a)
g<-t(e$b)
#Adding Legend
legend(x=range(co[,1])[2], y=range(co[,2])[2],
legend=as.character(f),
pch=21,
col = "#777777",
pt.bg=as.character(g),
pt.cex=4,
bty="n",
ncol=1,
lty=1,
cex = .5)
#Adding Title
title("Network Average Weighted Neighbor Degree Sized - 1.1 - REDE COMPLETA (full_no_zero)", sub = "Source: from authors ")
text(x=range(co[,1])[1], y=range(co[,2])[1], labels =
sprintf("Median Average Weighted Neighbor Degree: %.2f",
median((full_no_zero_a.nn.deg_w+1))
))
#Circle Degree ***Too intense computation***
#A_full_no_zero <- get.adjacency(full_no_zero, sparse=FALSE)
#detach("package:igraph", unload=TRUE)
#library(network)
#g <- network::as.network.matrix(A_full_no_zero)
#library(sna)
#gplot.target(g, degree(g), main="Circle Degree")
#library(igraph)
save.image("~/SNArRDJF/Robject/full_no_zero_data.RData")